define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dressup/index' + location.search,
                    add_url: 'dressup/add',
                    edit_url: 'dressup/edit',
                    del_url: 'dressup/del',
                    multi_url: 'dressup/multi',
                    import_url: 'dressup/import',
                    table: 'dressup',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'category_id', title: __('Category_id')},
                        {
                            field: 'type_list',
                            title: __('TypeList'),
                            searchList: {"virtual": __('TypeList virtual'), "physical": __('TypeList physical')},
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'is_free',
                            title: __('IsFree'),
                            searchList: {"Y": __('IsFree Y'), "N": __('IsFree N')},
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'category.name', title: __('Category.name'), operate: 'LIKE'},
                        // {field: 'goods_id', title: __('Goods_id')},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"0": __('Status 0'), "1": __('Status 1')},
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'product.name', title: __('Product.name'), operate: 'LIKE'},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            $("select[name='row[type_list]']").change(function () {

                var typelist = $("select[name='row[type_list]']").val();
                console.log(typelist);
                if (typelist == "virtual") {
                    $('#product_id').hide();
                } else {
                    $('#product_id').show();
                }
            }).trigger('change');
        },
        edit: function () {
            Controller.api.bindevent();

            $("select[name='row[type_list]']").change(function () {

                var typelist = $("select[name='row[type_list]']").val();

                if (typelist == "virtual") {
                    $('#product_id').hide();
                } else {
                    $('#product_id').show();
                }
            }).trigger('change');


        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
